var reviveCount = 5;
var mapIds = [867111060, 867111080, 867111100, 867111120, 867111140, 867111150, 867111170, 867111180, 867111200, 867111220, 867111240, 867111260, 867111270, 867111290, 867111300, 867111320, 867111340, 867111350, 867111030, 867111031, 867111032];
var 准备地图 = 867110000;
var eventName = "副本_APORD飞船_剧情";

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance(eventName);
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(false)
    }
    return c
}

function onPlayerRegistered(b, a) {
    if (a.getQuestStatus(59728) == 1) {
        var c = b.getMapInstance(867111060)
    } else {
        if (a.getQuestStatus(59729) == 1) {
            var c = b.getMapInstance(867111150)
        } else {
            if (a.getAPI().isQuestFinished(59730) && a.getAPI().getQuestStatus(59731) == 0) {
                var c = b.getMapInstance(867111170)
            } else {
                if (a.getQuestStatus(59731) == 1) {
                    var c = b.getMapInstance(867111200)
                } else {
                    if (a.getQuestStatus(59732) == 1) {
                        var c = b.getMapInstance(867111270)
                    } else {
                        if (a.getAPI().isQuestFinished(59733) && a.getAPI().getQuestStatus(59734) == 0) {
                            var c = b.getMapInstance(867111290)
                        } else {
                            if (a.getQuestStatus(59734) == 1) {
                                var c = b.getMapInstance(867111350)
                            } else {
                                var c = b.getMapInstance(867111060)
                            }
                        }
                    }
                }
            }
        }
    }
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(45 * 60 * 1000)
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    em.setProperty("kill", "0");
    if (a == 867111180) {
        em.setProperty("clear", "1")
    } else {
        em.setProperty("clear", "0")
    }
    em.setProperty("curMap", a)
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(c, d) {
    var b = player.getMapId();
    if (b == 867111150 || b == 867111270 || b == 867111350) {
        var e = 1
    } else {
        var e = 10
    }
    var a = em.getNumberProperty("kill") + 1;
    em.setProperty("kill", a);
    if (a == e) {
        player.getMap().getAllMonsters().forEach(function (f) {
            if (f.getId() != 9410883) {
                player.getMap().killMonster(d)
            }
        });
        if (b == 867111080) {
            player.getAPI().spawnMobLimit(9410881, 1, 0, 116, 1)
        } else {
            if (b == 867111060 || b == 867111100 || b == 867111120 || b == 867111200 || b == 867111220 || b == 867111240 || b == 867111300 || b == 867111320) {
                player.getAPI().spawnMobLimit(9410881, 1, 0, 46, 1)
            }
        }
        player.getAPI().fieldEffect_复合图片动画(["Map/EffectPL.img/3min/clearS/skeleton_clear", "animation_text01_01", "", ""], [0, 0, 1, 0, 0, 0, 0, 0]);
        player.getAPI().fieldEffect_PlayFieldSound("Party1/Clear");
        c.schedule("清图", 1800);
        c.schedule("结束特效", 3000)
    }
}

function 清图() {
    var a = parseInt(em.getProperty("curMap"));
    eim.getMapInstance(a).killMonster(9410883)
}

function 结束特效() {
    var a = parseInt(em.getProperty("curMap"));
    em.setProperty("clear", "1");
    eim.getPlayers().forEach(function (c) {
        var b = c.getMapId();
        if (b != a) {
            return
        }
        c.getAPI().openNpc(2540005, "APORD飞船_通关")
    })
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp(a) {}

function onMonsterDamaged(a) {};